import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../widgets/text_button.dart';
import 'ip_query_controller.dart';

class IpQueryPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetX<IpQueryController>(
        init: IpQueryController(),
        builder: (controller) {
          return Scaffold(
              appBar: AppBar(title: Text('ip地址查询')),
              body: Container(
                margin: EdgeInsets.all(15),
                child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        controller.result.value,
                        style: TextStyle(
                            color: Colors.deepPurpleAccent, fontSize: 17),
                      ),
                      _textButton('复制', width: 60, onPressed: () {
                        controller.copy();
                      })
                    ]),
              ));
        });
  }

  _textButton(String text, {double width = 90, Function? onPressed}) {
    return Container(
        width: width,
        height: 25,
        margin: EdgeInsets.only(top: 15),
        child: MyTextButton(
            text: text,
            confirm: () {
              onPressed?.call();
            },
            backgroundColor: Colors.deepPurpleAccent,
            textStyle: TextStyle(color: Colors.white)));
  }
}
